<?php

namespace Controller\Account;

class Add extends \Controller\Base {

    public function actionIndex() {
        $this->setMenuPath('Account', 'AccountList');
        if ($this->isPost()) {
            $this->add();
        }
        $groupList = \Business\Account::instance()->getGroupList();
        $this->assign('groupList', $groupList);
        $this->display();
    }

    private function add() {
        $account = $this->postParam('account');
        $password = $this->postParam('password');
        $groupId = $this->postInt('groupId');
        if (!$account) {
            $this->addWarningMsg('请填写账号');
            return;
        }
        if (!$password) {
            $this->addWarningMsg('请填写密码');
            return;
        }
        if (!$groupId) {
            $this->addWarningMsg('请选择分组');
            return;
        }
        $password = $this->encryptionPassword($password);
        \Business\Account::instance()->add($account, $password, $groupId);
        $this->addSuccessMsg('添加成功');
    }

}